import 'package:cbec_app/components/base/base_interactive.dart';
import 'package:cbec_app/components/common/common_style.dart';
import 'package:cbec_app/components/common/star_rating.dart';
import 'package:cbec_app/components/order/order_goods_item.dart';
import 'package:cbec_app/utils/Tools.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:get/get_core/src/get_main.dart';

import '../../routes/routes.dart';

class AfterSalesOrderItem extends StatefulWidget {
  ///订单ID
  final String id;

  ///订单号
  final String orderSn;

  ///订单时间
  final String orderTime;

  ///订单金额
  final double totalAmount;
  final int? returnStatus;

  ///订单商品列表
  final List goodsList;

  const AfterSalesOrderItem({
    super.key,
    required this.orderSn,
    required this.orderTime,
    required this.totalAmount,
    required this.goodsList,
    required this.id,
    this.returnStatus,
  });

  @override
  State<AfterSalesOrderItem> createState() => _AfterSalesOrderItemState();
}

class _AfterSalesOrderItemState extends State<AfterSalesOrderItem> {
  late Widget actionButtons;
  //操作按钮组
  late Widget statusWidget;

  @override
  void initState() {
    super.initState();
  }

  //右上角的状态
  @override
  Widget build(BuildContext context) {
    //后面这里根据传参加判断
    final returnStatusStr = RefundStatusExtension.fromInt(widget.returnStatus!)?.description ?? '';
    print('returnStatusStr ====== $returnStatusStr');
    statusWidget = Text(returnStatusStr, style: TextStyle(fontSize: 11, fontWeight: FontWeight.w300, color: Tools.fromHex("#F83F2D")));

    return BaseInteractive(
      onClick: () => {Get.toNamed(Routes.afterSalesDetail, arguments: widget.id)},
      childWidget: Container(
        margin: EdgeInsets.only(bottom: 10.w),
        decoration: border_radis(Colors.white),
        // height: 200,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            //标题栏
            Container(
              padding: EdgeInsets.all(10.w),
              // height: 28,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Text(
                    "订单编号：${widget.orderSn}",
                    style: const TextStyle(fontSize: 13, fontWeight: FontWeight.w300),
                  ),
                  statusWidget
                ],
              ),
            ),
            //订单的商品列表
            Container(
              padding: EdgeInsets.only(left: 10.w, right: 10.w),
              child: Column(
                children: [
                  //这里面是商品
                  for (var goodsItem in widget.goodsList)
                    OrderGoodsItem(
                      goodsImg: goodsItem['img'] ?? '',
                      title: goodsItem['goodsName'] ?? '',
                      tags: goodsItem['tags'],
                      price: goodsItem['price'],
                      num: goodsItem['returnNumber'],
                      totalAmount: widget.totalAmount,
                      refundAmount: goodsItem['priceActual'],
                      returnStatus: widget.returnStatus,
                    ),
                  //这里是实付款
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}
